package com.willpower.eureka.auth.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
 * @author: wen-yi;
 * @date: 2021/11/2 21:29;
 * @Description:
 */
@Data
public class Result {
    @ApiModelProperty("是否成功")
    private Boolean status;
    @ApiModelProperty("返回码")
    private Integer code;
    @ApiModelProperty("返回消息")
    private String msg;
    @ApiModelProperty("返回数据")
    private Object data;
    private Result(){}

    private Result(CustomizeResultCode result, Object data){
        this.status = result.getCode()==200;
        this.code = result.getCode();
        this.msg = result.getMessage();
        this.data = data;
    }

    public static Result ok(){
        return new Result(ResultCode.SUCCESS,null);
    }
    public static Result ok(Object data){
        return new Result(ResultCode.SUCCESS,data);
    }

    public static Result fail(){
        return new Result(ResultCode.COMMON_FAIL,null);
    }
    public static Result fail(CustomizeResultCode result){
        return new Result(result,null);
    }
    public static Result fail(CustomizeResultCode result,Object data){
        return new Result(result,data);
    }

    /*链式编程*/
    public Result setCode(Integer code){
        this.code = code;
        return this;
    }
    public Result setMessage(String message){
        this.msg = message;
        return this;
    }
    public Result setData(Object data){
        this.data = data;
        return this;
    }
}
